from Base import message, intersect, SS_VALID
from DRG import MDCO_DRG

def group(record):
  adrg_zd = ["O01.001","O01.101","O01.102","O01.901","O01.902","O02.100x002","O03.903","O04.502","O04.800x061","O04.801","O04.802","O04.901","O04.902","O08.103","O08.202","O35.002","O35.003","O35.004","O35.005","O35.006","O35.007","O35.008","O35.009","O35.010","O35.101","O35.102","O35.200x002","O35.200x003","O35.200x004","O35.201","O35.202","O35.203","O35.204","O35.205","O35.206","O35.800x003","O35.800x005","O35.800x006","O35.800x007","O35.800x009","O35.800x010","O35.800x011","O35.800x012","O35.800x015","O35.800x017","O35.800x018","O35.800x019","O35.800x020","O35.800x023","O35.800x025","O35.800x026","O35.800x027","O35.800x030","O35.801","O35.803","O35.804","O35.805","O35.806","O35.807","O35.808","O35.809","O35.810","O35.811","O35.812","O35.813","O35.814","O35.816","O35.817","O35.818","O35.819","O35.820","O35.821","O35.822","O35.823","O36.401"]
  adrg_zd1 = ["O02.100"]
  adrg_zd2 = ["O26.900x109","O26.900x201","O26.900x202","O26.900x203","O26.900x204","O26.900x205","O26.900x206","O26.900x301","O26.900x302","O26.900x303","O26.900x304","O26.900x305","O26.900x306","O26.900x401"]
  adrg_ss = ["68.0x00x007","69.0100x002","69.0200x003","69.5202","69.5901","73.1x01","73.1x02","73.8x00x003","74.9100","74.9100x001","74.9101","75.0x01","75.0x01x001","75.0x02"]
  adrg_ss1 = []
  dept_list = []

  if (record.zdList[0] in adrg_zd and record.ssList and record.ssList[0] in adrg_ss)  or\
     (record.zdList[0]=="O02.100" and intersect (record.zdList[1:], adrg_zd2)\
      and record.ssList and record.ssList[0] in adrg_ss):
    
    if record.zdList[0] in adrg_zd and record.ssList and record.ssList[0] in adrg_ss:
      message('符合OF1入组条件1，匹配规则：主要诊断 1+主要手术或操作')
    else:
      message('符合OF1入组条件2，匹配规则：主要诊断 2+其他诊断+主要手术或操作')
      
    if MDCO_DRG.OF19_group(record):
      return 'OF19'
          
    return 'OF1'
  else:
    return ''

